package com.seo.controller.index;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.seo.pojo.ReturnBody;
import com.seo.service.report.sdk.ReportService;
import com.seo.service.sysUser.sdk.SysUserService;
import com.seo.utils.ClientConst;
import com.seo.utils.Jurisdiction;

import lombok.extern.slf4j.Slf4j;

/**
 * 首页controller <br/>
 * 
 * @author shibeilei
 * @version 2017.11.30 12:20
 */
@Slf4j
@Controller
@RequestMapping(value = "/report")
public class ReportController {

	@Autowired
	private ReportService reportService;
	
	@Autowired
	private SysUserService sysUserService;

	@RequestMapping
	public String report(Integer parantId, HttpServletRequest request, HttpSession session) {
		log.info("进入首页报表...");

		return "report/index";

	}
	
	@RequestMapping("/v2")
	public String v2(Integer parantId, HttpServletRequest request, HttpSession session) {
		log.info("进入首页报表...");
		ReturnBody rb = ReturnBody.init();
		Map<String, Object> params = new HashMap<>();
		Integer id = Jurisdiction.getT("id", Integer.class, ClientConst.SESSION_USER);
		Map<String, Object> sysUser = sysUserService.getSysUserById(id);
		String dataAuthority = (String)sysUser.get("dataAuthority");
		if("00".equals(dataAuthority)) {
			params.put("belongId", id);
		}
		
		rb.run(reportService.getReportNewIndex(params));
		request.setAttribute("resultList", rb.get("resultList"));
		request.setAttribute("resultEList", rb.get("resultEList"));
		return "report/index_v2";

	}

	@RequestMapping("/getReportIndex")
	@ResponseBody
	public ReturnBody getReportIndex() {
		log.info("获取首页报表...");
		ReturnBody rb = ReturnBody.init();
		rb.run(reportService.getReportIndex());

		return rb;
	}

}
